package com.jinmdz.fmis.mapper.mapper.provider;

import com.jinmdz.fmis.mapper.entity.ChargeVerifyEntity;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * 日结审核表Provider
 *
 * @author generator
 * @date 2020-03-12 17:08
 */
public class ChargeVerifyProvider {

    /**
     * 增加ChargeVerify
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String insertChargeVerify(@Param("entity") ChargeVerifyEntity entity) {
        return new SQL() {
            {
                INSERT_INTO(" charge_verify ");

                if (entity.getDeleted() != null) {
                    VALUES(" deleted ", " #{entity.deleted,jdbcType=TINYINT} ");
                }

                VALUES(" verify_batch_no ", " #{entity.verifyBatchNo,jdbcType=VARCHAR} ");
                VALUES(" verify_charge ", " #{entity.verifyCharge,jdbcType=DECIMAL} ");
                VALUES(" verify_time ", " #{entity.verifyTime,jdbcType=TIMESTAMP} ");
                VALUES(" invoice_count ", " #{entity.invoiceCount,jdbcType=INTEGER} ");
                VALUES(" receipt_count ", " #{entity.receiptCount,jdbcType=INTEGER} ");
                VALUES(" verify_user_id ", " #{entity.verifyUserId,jdbcType=INTEGER} ");
                VALUES(" remark ", " #{entity.remark} ");
                VALUES(" funeral_parlour_code ", " #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                VALUES(" create_user_id ", " #{entity.createUserId,jdbcType=INTEGER} ");

                if (entity.getUnmodified() != null) {
                    VALUES(" unmodified ", " #{entity.unmodified,jdbcType=TINYINT} ");
                }

                VALUES(" modified_user_id ", " #{entity.modifiedUserId,jdbcType=INTEGER} ");
                VALUES(" version ", " unix_timestamp(now()) ");
            }
        }.toString();
    }

    /**
     * 修改ChargeVerify
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String updateChargeVerify(@Param("entity") ChargeVerifyEntity entity) {
        return new SQL() {
            {
                UPDATE(" charge_verify ");

                if (entity.getDeleted() != null) {
                    SET(" deleted = #{entity.deleted,jdbcType=TINYINT} ");
                }

                SET(" verify_batch_no = #{entity.verifyBatchNo,jdbcType=VARCHAR} ");
                SET(" verify_charge = #{entity.verifyCharge,jdbcType=DECIMAL} ");
                SET(" verify_time = #{entity.verifyTime,jdbcType=TIMESTAMP} ");
                SET(" invoice_count = #{entity.invoiceCount,jdbcType=INTEGER} ");
                SET(" receipt_count = #{entity.receiptCount,jdbcType=INTEGER} ");
                SET(" verify_user_id = #{entity.verifyUserId,jdbcType=INTEGER} ");
                SET(" remark = #{entity.remark} ");
                SET(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");

                if (entity.getUnmodified() != null) {
                    SET(" unmodified = #{entity.unmodified,jdbcType=TINYINT} ");
                }

                SET(" modified_user_id = #{entity.modifiedUserId,jdbcType=INTEGER} ");
                SET(" version = unix_timestamp(now()) ");
                WHERE(" id = #{entity.id,jdbcType=INTEGER} ");
                WHERE(" unmodified = 0 ");
                WHERE(" version = #{entity.version,jdbcType=INTEGER} ");
            }
        }.toString();
    }

    /**
     * 查询ChargeVerify列表
     *
     * @param entity 数据实体
     * @return String
     * @author generator
     * @date 2020-03-12 17:08
     */
    public String listChargeVerify(@Param("entity") ChargeVerifyEntity entity) {
        return new SQL() {
            {
                StringBuilder builder = new StringBuilder();
                builder.append(" id,deleted,verify_batch_no,verify_charge,verify_time,invoice_count,receipt_count,verify_user_id,remark,funeral_parlour_code,create_user_id,gmt_create,unmodified,modified_user_id,gmt_modified,version ");
                SELECT(builder.toString());
                FROM(" charge_verify ");

                if (entity.getVerifyBatchNo() != null) {
                    WHERE(" verify_batch_no = #{entity.verifyBatchNo,jdbcType=VARCHAR} ");
                }

                if (entity.getVerifyCharge() != null) {
                    WHERE(" verify_charge = #{entity.verifyCharge,jdbcType=DECIMAL} ");
                }

                if (entity.getVerifyTime() != null) {
                    WHERE(" verify_time = #{entity.verifyTime,jdbcType=TIMESTAMP} ");
                }

                if (entity.getInvoiceCount() != null) {
                    WHERE(" invoice_count = #{entity.invoiceCount,jdbcType=INTEGER} ");
                }

                if (entity.getReceiptCount() != null) {
                    WHERE(" receipt_count = #{entity.receiptCount,jdbcType=INTEGER} ");
                }

                if (entity.getVerifyUserId() != null) {
                    WHERE(" verify_user_id = #{entity.verifyUserId,jdbcType=INTEGER} ");
                }

                if (entity.getRemark() != null) {
                    WHERE(" remark = #{entity.remark} ");
                }

                if (entity.getFuneralParlourCode() != null) {
                    WHERE(" funeral_parlour_code = #{entity.funeralParlourCode,jdbcType=VARCHAR} ");
                }

            }
        }.toString();
    }
}